package com.fs.open.web;

import com.fs.sys.bean.dto.UserDTO;
import com.fs.sys.entityservice.UserEntityService;
import jakarta.annotation.security.PermitAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户开放接口
 *
 * @author  LiuQi 2025/9/30-9:41
 * @version V1.0
 **/
@RestController
@RequestMapping("/open/user")
@PermitAll
public class OpenUserController {
    @Autowired
    private UserEntityService userEntityService;

    @GetMapping("list")
    public List<UserDTO> findAll() {
        return userEntityService.queryBuilder()
                .eq("deleted", 0)
                .query()
                .stream()
                .peek(user -> user.setPassword(null))
                .toList();
    }

    @GetMapping("detail/{id}")
    public UserDTO getDetail(@PathVariable("id") String id) {
        return userEntityService.findById(id)
                .map(user -> {
                    user.setPassword(null);
                    return user;
                }).orElse(null);
    }
}
